﻿using CommonEngine;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace CommonDevelop
{
    /// <summary>
    /// 统一数据层的基础操作接口
    /// </summary>
    public interface IBase<T> where T : class, new()
    {
        Expression<Func<T, bool>> WhereKeyWord(string keyword);
        Expression<Func<T, object>> AddColumns();

        T GetEntity(object keyValue);
        T GetEntity(Expression<Func<T, bool>> expression, bool IsDelete);

        IEnumerable<T> GetList(string keyword = null, bool IsDelete = false);
        IEnumerable<T> GetList(Expression<Func<T, bool>> expression, bool IsDelete = false);
        IEnumerable<T> GetPageList(Pagination Pag, Expression<Func<T, bool>> expression, bool IsDelete = false);
        IEnumerable<T> GetPageList(Pagination Pag, string keyword = null, bool IsDelete = false);

        IEnumerable<TVO> GetPull<TVO>(T en) where TVO : class, new();
        IEnumerable<T> GetPush<TVO>(TVO en) where TVO : class, new();

        bool IsExist(Expression<Func<T, bool>> predicate);
        int Add_Entities(IEnumerable<T> EnLs, bool Trans);
        int Update_Entities(IEnumerable<T> EnLs, bool Trans, Expression<Func<T, object>> Columns = null);

        bool Add_Entity(T En, bool Trans);
        bool Update_Entity(T En, bool Trans);
        bool Update_EntityIgnore(T En, Expression<Func<T, object>> IgnoreColumns);
        bool Update_EntityColumns(T En, Expression<Func<T, object>> columns);
        bool Update_Batch(Expression<Func<T, T>> columns, Expression<Func<T, bool>> expression);

        bool Delete(params long[] keyValue);
        bool Delete(params string[] keyValue);
        bool Delete_Batch(Expression<Func<T, bool>> expression);
        bool Delete_Entity(T En);
    }
}
